local skel = fk.CreateSkill {
  name = "emo__qianfang",
}

Fk:loadTranslationTable{
  ["emo__qianfang"] = "倩放",
  [":emo__qianfang"] = "结束阶段，你可以视为对拥有一种颜色的“梅”标记的所有角色使用【以逸待劳】。",

  ["#emo__qianfang-choice"] = "倩放：选择一种颜色，对有此颜色的“梅”标记的所有角色使用【以逸待劳】",
}

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) and player.phase == Player.Finish then
      return table.find(player.room.alive_players, function (p)
        return p:getMark("@emoPlum") ~= 0
      end)
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local choices = {}
    local map = {}
    for _, p in ipairs(room:getAlivePlayers()) do
      local color = p:getMark("@emoPlum")
      if color ~= 0 then
        table.insertIfNeed(choices, color)
        map[color] = map[color] or {}
        table.insert(map[color], p)
      end
    end
    table.insert(choices, "Cancel")
    local choice = room:askToChoice(player, {choices = choices, skill_name = skel.name, prompt = "#emo__qianfang-choice" })
    if choice ~= "Cancel" then
      local tos = map[choice]
      event:setCostData(self, {tos = tos})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local tos = event:getCostData(self).tos
    room:useVirtualCard("await_exhausted", nil, player, tos, skel.name)
  end,
})

return skel
